home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / fe1.zip / FE.CPP < prev    next >
C/C++ Source or Header  |  1992-02-07  |  3KB  |  124 lines

  1. #include <ctype.h>
  2. #include <bios.h>
  3.  
  4. #include "fe.h"
  5.  
  6. boxes :: boxes ( size_t sz ) : size( sz ), point( 0 ) {
  7.  
  8.     comd = new fg_pbox_t [sz] ;
  9.     comdscripts = new eventscript_t [sz] ;
  10.     for ( size_t i = 0 ; i < sz ; i++ ) {
  11.         comd[i] = new fg_box_t ;
  12.         fg_make_box( comd[i], 0, 0, 0, 0 ) ;
  13.         comdscripts[i] = NULL ;
  14.     }
  15. }
  16.  
  17. void boxes :: add_script ( fg_pbox_t c, eventscript_t s ) {
  18.  
  19.     if ( point < size ) {
  20.         fg_box_cpy( comd[point], c ) ;
  21.         comdscripts[point] = s ;
  22.         point++ ;
  23.     }
  24. }
  25.  
  26. void boxes :: translate_script ( win *w, fg_coord_t x, fg_coord_t y ) {
  27.  
  28.     for ( size_t i = 0 ; i < point ; i++ )
  29.         if ( fg_pt_inbox( comd[i], x, y ) )
  30.             if ( comdscripts[i] )
  31.                 ( w->*comdscripts[i] )() ;
  32. }
  33.  
  34. keyboard :: keyboard ( size_t sz ) : size( sz ), point( 0 ) {
  35.  
  36.     comd = new char [sz] ;
  37.     comdscripts = new eventscript_t [sz] ;
  38.     for ( size_t i = 0 ; i < sz ; i++ ) {
  39.         comd[i] = NULL ;
  40.         comdscripts[i] = NULL ;
  41.     }
  42. }
  43.  
  44. void keyboard :: add_script ( char c, eventscript_t s ) {
  45.  
  46.     if ( point < size ) {
  47.         comd[point] = c ;
  48.         comdscripts[point] = s ;
  49.         point++ ;
  50.     }
  51. }
  52.  
  53. void keyboard :: translate_script ( win *w, char c ) {
  54.  
  55.     for ( size_t i = 0 ; i < point ; i++ )
  56.         if ( toupper( comd[i] ) == toupper( c ) )
  57.             if ( comdscripts[i] )
  58.                 ( w->*comdscripts[i] )() ;
  59. }
  60.  
  61. void win :: focus_loop ( win *w ) {
  62.  
  63.     int status, last_status ;
  64.     unsigned x, y ;
  65.  
  66.     while ( !quit ) {
  67.         if ( bioskey( 1 ) ) {
  68.             activate_key = ( char )( bioskey( 0 ) & 0xff ) ;
  69.             kbd->translate_script( w, activate_key ) ;
  70.         } else if ( ( status = msm_getstatus( &x, &y ) )
  71.             != last_status && status )
  72.             box->translate_script(
  73.                 w, x, fg.displaybox[FG_Y2] + 1 - y
  74.             ) ;
  75.             
  76.         last_status = status ;
  77.     }
  78.     msm_hidecursor() ;
  79.     clear() ;
  80.     msm_showcursor() ;
  81.     expose_parent() ;
  82. }
  83.  
  84. menu :: menu (
  85.     fg_coord_t x, fg_coord_t y, size_t w, size_t sz, win *p
  86. ) : win( x, y, fg.charbox[FG_X2] * ( w + 2 ),
  87.     fg.charbox[FG_Y2] * sz, FG_LIGHT_WHITE, FG_CYAN, p, sz, sz ),
  88.     size( sz ), point( 0 )
  89. {
  90.     i_names = new char * [sz] ;
  91. }
  92.  
  93. void menu :: add_item ( char c, char *name, eventscript_t s ) {
  94.  
  95.     fg_box_t b ;
  96.  
  97.     if ( point < size ) {
  98.         i_names[point] = name ;
  99.         kbd->add_script( c, s ) ;
  100.         fg_box_cpy( b, winbox ) ;
  101.         b[FG_Y1] = y + fg.charbox[FG_Y2] * ( size - point - 1 ) ;
  102.         b[FG_Y2] = b[FG_Y1] + fg.charbox[FG_Y2] ;
  103.         box->add_script( b, s ) ;
  104.         point++ ;
  105.     }
  106. }
  107.  
  108. void menu :: expose () {
  109.  
  110.     msm_hidecursor() ;
  111.     cls() ;
  112.     for ( size_t i = 0 ; i < point ; i++ )
  113.         fg_puts( fgc, FG_MODE_SET, ~0, FG_ROT0,
  114.             x + fg.charbox[FG_X2],
  115.             y + ( size - i - 1 ) * fg.charbox[FG_Y2],
  116.             i_names[i], winbox ) ;
  117.     msm_showcursor() ;
  118. }
  119.  
  120. void menu :: focus () { focus_loop( parent ) ; }
  121.  
  122. void menu :: destroy () { quit = 1 ; }
  123.  
  124.